package com.czk.rdd.operator.action

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author:ChenZhangKun
 * @Date: 2021/12/10 14:23
 */
object Fold {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("RDD")
    val sc = new SparkContext(sparkConf)
    val rdd = sc.makeRDD(List(1,2,3,4))

    // 折叠操作，aggregate 的简化版操作 区内和区间计算规则可以简化
    val i= rdd.fold(0)(_+_)

    println(i)
  }
}
